home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Tcl-Tk 8.0 / Pre-installed version / tcl8.0 / tests / split.test < prev    next >
Encoding:
Text File  |  1997-08-15  |  1.9 KB  |  66 lines  |  [TEXT/ALFA]

  1. # Commands covered:  split
  2. #
  3. # This file contains a collection of tests for one or more of the Tcl
  4. # built-in commands.  Sourcing this file into Tcl runs the tests and
  5. # generates output for errors.  No output means no errors were found.
  6. #
  7. # Copyright (c) 1991-1993 The Regents of the University of California.
  8. # Copyright (c) 1994-1996 Sun Microsystems, Inc.
  9. #
  10. # See the file "license.terms" for information on usage and redistribution
  11. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  12. #
  13. # SCCS: @(#) split.test 1.10 97/07/07 16:30:07
  14.  
  15. if {[string compare test [info procs test]] == 1} then {source defs}
  16.  
  17. test split-1.1 {basic split commands} {
  18.     split "a\n b\t\r c\n "
  19. } {a {} b {} {} c {} {}}
  20. test split-1.2 {basic split commands} {
  21.     split "word 1xyzword 2zword 3" xyz
  22. } {{word 1} {} {} {word 2} {word 3}}
  23. test split-1.3 {basic split commands} {
  24.     split "12345" {}
  25. } {1 2 3 4 5}
  26. test split-1.4 {basic split commands} {
  27.     split "a\}b\[c\{\]\$"
  28. } "a\\}b\\\[c\\{\\\]\\\$"
  29. test split-1.5 {basic split commands} {
  30.     split {} {}
  31. } {}
  32. test split-1.6 {basic split commands} {
  33.     split {}
  34. } {}
  35. test split-1.7 {basic split commands} {
  36.     split {   }
  37. } {{} {} {} {}}
  38. test split-1.8 {basic split commands} {
  39.     proc foo {} {
  40.         set x {}
  41.         foreach f [split {]\n} {}] {
  42.             append x $f
  43.         }
  44.         return $x    
  45.     }
  46.     foo
  47. } {]\n}
  48. test split-1.9 {basic split commands} {
  49.     proc foo {} {
  50.         set x ab\000c
  51.         set y [split $x {}]
  52.         return $y
  53.     }
  54.     foo
  55. } "a b \000 c"
  56. test split-1.10 {basic split commands} {
  57.     split "a0ab1b2bbb3\000c4" ab\000c
  58. } {{} 0 {} 1 2 {} {} 3 {} 4}
  59.  
  60. test split-2.1 {split errors} {
  61.     list [catch split msg] $msg $errorCode
  62. } {1 {wrong # args: should be "split string ?splitChars?"} NONE}
  63. test split-2.2 {split errors} {
  64.     list [catch {split a b c} msg] $msg $errorCode
  65. } {1 {wrong # args: should be "split string ?splitChars?"} NONE}
  66.